package com.aaa.controller;

import com.aaa.entity.MyReturn;
import com.aaa.entity.ViewTestResultSas;
import com.aaa.service.ViewTestResultSasService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (ViewTestResultFpa)表控制层
 *
 * @author
 * @since 2022-07-08 10:00:04
 */
@RestController
@RequestMapping("viewTestResultSas")
public class ViewTestResultSasController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ViewTestResultSasService viewTestResultSasService;
    MyReturn myReturn = new MyReturn();

    @RequestMapping("toShowTestResultSas.do")
    public ModelAndView toShowTestResultSas(ModelAndView modelAndView) {
        modelAndView.setViewName("viewTestResultSas");
        return modelAndView;
    }

    @RequestMapping("toReportFormsSas.do")
    public ModelAndView toReportFormsSas(ModelAndView modelAndView) {
        modelAndView.setViewName("reportFormsSas");
        return modelAndView;
    }

    /**
     * 分页查询
     *
     * @param viewTestResultSas 筛选条件
     * @return 查询结果
     */
    @RequestMapping("queryByPage.do")
    public ResponseEntity<Page<ViewTestResultSas>> queryByPage(ViewTestResultSas viewTestResultSas, Integer page, Integer limit) {
        PageRequest pageRequest = PageRequest.of(page - 1, limit);
        return ResponseEntity.ok(this.viewTestResultSasService.queryByPage(viewTestResultSas, pageRequest));
    }

    /**
     * @param viewTestResultSas
     * @return MyReturn
     * @create by: feng (zhaixing@163.com)
     * @description: 根据id查询对应信息
     * @create time: 2022/7/15 15:48
     */
    @RequestMapping("queryResultById.do")
    public MyReturn queryResultById(ViewTestResultSas viewTestResultSas) {
        ViewTestResultSas result = this.viewTestResultSasService.queryRequestById(viewTestResultSas);
        myReturn.setData(result);
        return getSuccessResult(myReturn);
    }

    /**
     * @param
     * @return MyReturn
     * @create by: feng (zhaixing@163.com)
     * @description: 查询所有数据 报表统计
     * @create time: 2022/7/15 16:17
     */
    @RequestMapping("sasCount.do")
    public MyReturn colorCount() {
        Map<String, Integer> map = this.viewTestResultSasService.queryAllPlanSas();
        myReturn.setData(map);
        return getSuccessResult(myReturn);
    }

    /**
     * @param
     * @return MyReturn
     * @create by: feng (zhaixing@163.com)
     * @description: 查询所有 下拉列表
     * @create time: 2022/7/19 21:08
     */
    @RequestMapping("pullSas.do")
    public MyReturn pullSas() {
        List<ViewTestResultSas> viewTestResultSas = this.viewTestResultSasService.queryAllResultSas();
        myReturn.setData(viewTestResultSas);
        return getSuccessResult(myReturn);
    }
    /**
     * @create by: feng (zhaixing@163.com)
     * @description: 删除
     * @create time: 2022/7/22 20:10
     * @param testerId
     * @return
     */
    @RequestMapping("deleteResultSas.do")
    public MyReturn deleteResultSas(String testerId){
        boolean b = this.viewTestResultSasService.deleteResultById(testerId);
        if (b) {
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }


}

